{extend name="admin/common/base" /}
{block name="content"}
<div class="row">
<form class="form-horizontal" action="{:url('admin/article/save')}" method="post">
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="cid"> {:lang('文章分类')} </label>
    <div class="col-sm-9">
    <select id="cid" name="cid" class="col-xs-10 col-sm-5">
        {volist name="category" id="v"}
        <option value="{$v.id}">{$v.name}</option>
        {notempty name="v.children"}
        {volist name="v.children" id="vv"}
        <option value="{$vv.id}">┣━{$vv.name}</option>
        {notempty name="vv.children"}
        {volist name="vv.children" id="vvv"}
        <option value="{$vvv.id}">┣━━{$vvv.name}</option>
        {notempty name="vvv.children"}
        {volist name="vvv.children" id="vvvv"}
        <option value="{$vvvv.id}">┣━━{$vvvv.name}</option>
        {/volist}
        {/notempty}
        {/volist}
        {/notempty}
        {/volist}
        {/notempty}
        {/volist}
    </select>
    <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
        </span>
    </div>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="title"> {:lang('文章标题')} </label>
    <div class="col-sm-9">
        <input type="text" name="title" id="title" class="col-xs-10 col-sm-5" value="" required="required">
        <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
        </span>
    </div>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="stick"> {:lang('文章置顶')} </label>
    <div class="control-label no-padding-left col-sm-1">
        <label>
            <input name="stick" id="stick" value="1" class="ace ace-switch ace-switch-2" type="checkbox" />
            <span class="lbl"></span>
        </label>
    </div>
    <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
    </span>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="image"> {:lang('缩略图')} </label>
    <div class="col-sm-9">
        <div class="col-xs-10 col-sm-5">{:upload_image("image",100,100,'')}</div>
        <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle">{:lang('仅支持jpg、gif、png、bmp、jpeg。')}</span>
        </span>
    </div>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="keywords"> {:lang('关键词')} </label>
    <div class="col-sm-9">
        <input type="text" name="keywords" id="keywords" class="col-xs-10 col-sm-5" value="" required="required">
        <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
        </span>
    </div>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="description"> {:lang('文章摘要')} </label>
    <div class="col-sm-9">
        <textarea name="description" id="description" placeholder="{:lang('文章摘要')}" class="col-xs-10 col-sm-5" rows="5"></textarea>
        <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
        </span>
    </div>
</div>
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="description"> {:lang('文章内容')} </label>
    <div class="col-sm-9">
        <textarea name="content" id="content" class="col-xs-10 col-sm-10 col-md-10 col-lg-12" style="height:500px;"></textarea>
        <span class="help-inline col-xs-12 col-sm-7">
            <span class="middle"></span>
        </span>
    </div>
</div>

<div class="space-4"></div>
<div class="col-md-offset-2 col-md-9">
    <button id="submit" class="btn btn-info" type="submit">
        <i class="icon-ok bigger-110"></i>
        {:lang('提交')}
    </button>

    &nbsp; &nbsp; &nbsp;
    <button class="btn" type="reset">
        <i class="icon-undo bigger-110"></i>
        {:lang('重置')}
    </button>
</div>
</form>
</div>
{/block}
{block name="js_file"}
<script src="/static/tinymce/tinymce.min.js"></script>
{/block}
{block name="javascript"}
<script type="text/javascript">
    $(function(){
      tinymce.init({
        selector: '#content',
        {if $lang != 'en-us'}language:'{$lang}',{/if}
        //menubar: false,
        menubar: 'file edit view insert format tools table help',
        license_key: 'gpl',
        branding: false,
        promotion: false,
        plugins: ['accordion','advlist','anchor','autolink','charmap','code','codesample','directionality','emoticons','fullscreen','help','image','importcss','insertdatetime','link','lists','media','nonbreaking','pagebreak','preview','searchreplace','table','visualblocks','visualchars','wordcount'],
        toolbar:'undo redo blocks fontfamily fontsize bold italic underline strikethrough numlist bullist align lineheight outdent indent  removeformat table charmap emoticons link image media code fullscreen',
        automatic_uploads: true,
        images_upload_url: '{:url('admin/upload/file')}',
        //images_upload_base_path: '/',
        relative_urls: false,
        file_picker_types: 'file image media',
        file_picker_callback: function(callback, value, meta) {
          var filetype='*.*';
          var upurl='{:url('admin/upload/file')}';
          switch(meta.filetype){
              case 'image':
                  filetype='.jpg, .jpeg, .png, .gif';
                  break;
              case 'media':
                  filetype='.mp3, .mp4, .mov, .aiv, .ogg';
                  break;
              case 'file':
              default:
          }
          var input = document.createElement('input');
              input.setAttribute('type', 'file');
              input.setAttribute('accept', filetype);
              input.click();
              input.onchange = function() {
                  var file = this.files[0];
                  var xhr, formData;
                  xhr = new XMLHttpRequest();
                  xhr.withCredentials = false;
                  xhr.open('POST', upurl);
                  xhr.onload = function() {
                      var json;
                      if (xhr.status != 200) {
                          failure('HTTP Error: ' + xhr.status);
                          return;
                      }
                      json = JSON.parse(xhr.responseText);
                      if (!json || typeof json.location != 'string') {
                          failure('Invalid JSON: ' + xhr.responseText);
                          return;
                      }
                      callback(json.location);
                  };
                  formData = new FormData();
                  formData.append('file', file, file.name );
                  xhr.send(formData);
            }
          },
      });
    })
</script>
{/block}
